<?php
/**
 * Created by PhpStorm.
 * User: yangc
 * Date: 2018/1/5
 * Time: 10:32
 */

namespace Xiaoc\Api;

/**
 * Xiaoc护妆 美妆页
 * @package Xiaoc\Api
 */
class Huzhuangmeizhuang extends Common
{
    public function getRules()
    {
        return array(
            'goodsList' => array(
                'page' => array('name' => 'page', 'desc' => '页数', 'default' => 1, 'require' => true),
                'limit' => array('name' => 'limit', 'desc' => '每页显示数', 'default' => 8, 'require' => true)
            )
        );
    }
    /**
     * 轮播图和明星产品
     * @desc 轮播图和明星产品
     * @return int ad_id 广告id
     * @return int ad_name 广告名字
     * @return string ad_link 广告链接
     * @return string ad_code (host+)图片路径
     * @return int goods_id 商品id
     * @return string goods_name 名称
     * @return float shop_price 价格
     * @return float shop_promote 促销价格
     * @return string goods_thumb (host+)图片路径
     */
    public function index()
    {
        $banner = \PhalApi\DI()
            ->notorm
            ->touch_ad
            ->select('ad_id, ad_name, ad_link,ad_code')
            ->where(array('position_id' => 262, 'start_time < ?' => gmtime(), 'end_time > ?' => gmtime()))
            ->order('ad_id desc')
            ->limit(0, 6);
        //明星产品
        $starGoods = \PhalApi\DI()
            ->notorm
            ->goods
            ->select('goods_id,shop_price,promote_price,goods_thumb')
            ->where(array('cat_id' => 1, 'is_best' => 1))
            ->order('last_update desc')
            ->limit(0, 3);
    }
    /**
     * 商品列表
     * @desc 商品列表
     * @param int page 页数
     * @param int limit 每页显示多少条
     * @return int goods_id ID
     * @return string goods_name 名称
     * @return float shop_price 价格
     * @return string goods_thumb (host+)图片路径
     * @return float market_price 市场价
     * @return string goods_brief 商品简介（副标题）
     * @return string goods_product_tag 商品标签（多个以,分割）
     */
    public function goodsList()
    {
        $page = $this->page;
        $limit = $this->limit;
        $limitNum = ($page - 1) * $limit;
        $list = \PhalApi\DI()
            ->notorm
            ->goods
            ->select('goods_id,goods_name,shop_price,market_price,goods_brief,goods_thumb,goods_product_tag')
            ->where(array('review_status > ?' => 2, 'goods_number > ?' => 0, 'is_on_sale' => 1, 'cat_id' => 5))
            ->order('goods_id desc')
            ->limit($limitNum, $limit);
        return $list;
    }
}